<?php
namespace Home\Controller;

use Vendor\Page;

class SendController extends ParentController
{
	/**
	 * 服务器推送事件
	 * */
	public function sendEvent(){
		//$rs = import("Home.Util.wechatCallbackapiTest");
		
		header('Content-type:text');
		
		$token = "hoFRrrrr3WIFYY9r3fc1hqodYWFyf9F4";		
		$wechatObj = new \Home\Model\callBackModel();
		if (!isset($_GET['echostr'])) {
			$wechatObj->responseMsg();
			$domain = $_SERVER['HTTP_HOST']; 
			
			//菜单
$jsonmenu = '{
      "button":[
	   {	
	   		"type":"view",
	   		"name":"阅读记录",
			"url":"http://qikaism.cn/Home/Novel/readhistory"
	   },
	   {	
	   		"type":"view",
	   		"name":"书城首页",
			"url":"http://qikaism.cn/Home/Index/index"
	   },
       {
           "name":"用户中心",
           "sub_button":[		   
		   {
               "type":"view",
               "name":"个人中心",
               "url":"http://qikaism.cn/Home/User/index"
            },
            {
               "type":"view",
               "name":"赠送书币",
               "url":"http://qikaism.cn/Home/User/getbookmoney"
            },
            {
               "type":"view",
               "name":"我要充值",
               "url":"http://qikaism.cn/Home/User/recharge"
            },
            {
                 "type":"click",
				 "name":"联系客服",
				 "key":"link"
            }]
       

       }]
 }';
			 
					
			$map["domain"] = $domain;
			$platform = D("platform")->where($map)->find();
			$access_token = "";
			if(intval($platform["out_time"]) > time())	{
				$access_token = getWeChatToken($platform["appid"],$platform["secret"],$platform["token"]);
			}
			else{
				$access_token = getWeChatToken($platform["appid"],$platform["secret"]);
			}		 
			
			
			$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
			//$result = weChatCurl($url, 1, $jsonmenu);
			//var_dump($result);
		}else{
			$wechatObj->valid($token);
		}
	}
}